package com.cn.lxz.android.aws;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

public class FileSlicer {
    public static List<InputStream> sliceFile(File file) throws IOException {
        List<InputStream> inputStreams = new ArrayList<>();
        long fileSize = file.length();
        long minSize = 4 * 1024 * 1024; // 4MB
        long maxSize = 100 * 1024 * 1024; // 100MB

        long currentPosition = 0;
        while (currentPosition < fileSize) {
            long remainingSize = fileSize - currentPosition;
            long sliceSize = Math.min(remainingSize, Math.min(maxSize, Math.max(minSize, remainingSize / 2)));
            byte[] buffer = new byte[(int) sliceSize];
            try (FileInputStream fis = new FileInputStream(file)) {
                fis.skip(currentPosition);
                fis.read(buffer);
            }
            inputStreams.add(new java.io.ByteArrayInputStream(buffer));
            currentPosition += sliceSize;
        }
        return inputStreams;
    }
}
